package com.amigo.online.provider.sync.handle.data.solr.service.impl;

import java.util.List;

import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.Query;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.stereotype.Service;

import com.amigo.online.provider.common.ConstantValue;
import com.amigo.online.provider.common.entity.MusicSolrInfo;
import com.amigo.online.provider.sync.common.AbstractGlobalService;
import com.amigo.online.provider.sync.handle.data.solr.service.MusicSolrService;

@Service
public class MusicSolrServiceImpl extends AbstractGlobalService implements MusicSolrService {

    @Autowired
    SolrTemplate solrTemplate;

    @Override
    public void insertObject(SolrInputDocument document) {
        UpdateResponse result = solrTemplate.saveDocument(ConstantValue.MUSIC_SOLR, document);
        solrTemplate.commit(ConstantValue.MUSIC_SOLR);
        logger.info("music solr 插入结果:" + result.toString());
    }

    @Override
    public long updateObject(String query, SolrInputDocument update) {
        UpdateResponse result = solrTemplate.saveDocument(ConstantValue.MUSIC_SOLR, update);
        solrTemplate.commit(ConstantValue.MUSIC_SOLR);
        logger.info("music solr 更新结果:" + result.toString());
        return 0;
    }

    @Override
    public long deleteObject(String query) {
        return 0;
    }

    @Override
    public List<MusicSolrInfo> listFindbyIds(List<Long> ids) {
        Query nequery = new SimpleQuery();
        nequery.addCriteria(Criteria.where("id").in(ids));
        List<MusicSolrInfo> result = solrTemplate.query(ConstantValue.MUSIC_SOLR, nequery, MusicSolrInfo.class);
        return result;
    }

}
